package cn.readjava.controller.manage;

import cn.readjava.bean.User;
import cn.readjava.service.UserService;
import cn.readjava.util.ResponseResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Controller
@RequestMapping("/manage/admin")
public class ManageAdminController {

    @Resource
    private UserService userService;

    // 预更新
    @GetMapping("/update/{id}")
    public String updateArticle(@PathVariable Long id, Model model) {
        User user = userService.getOne(id);
        model.addAttribute("user", user);
        return "manage/manage-admin-update";
    }

    // 更新
    @PostMapping("/update")
    @ResponseBody
    public Object updateArticle(User ur) {
        User user = userService.save(ur);
        if (user != null) {
            return new ResponseResult(200, "更新成功", user);
        }
        return new ResponseResult(100, "更新失败", null);
    }

   /* @GetMapping("/list")
    @RequiresRoles(RoleConstant.ROLE_ADMINISTRATOR)
    public String list(Model model) {
        List<User> userList = userService.findAllByLevelId(100);
        model.addAttribute("userList", userList);
        return "manage/manage-admin";
    }*/
}
